package com.atguigu.tingshu.payment.receiver;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.payment.service.PaymentInfoService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author atguigu-mqx
 * @ClassName PaymentReceiver
 * @description: TODO
 * @date 2024年01月09日
 * @version: 1.0
 */
@Component
public class PaymentReceiver {

    @Autowired
    private PaymentInfoService paymentInfoService;

    /**
     * 监听消息取消交易记录
     * @param record
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_PAYMENT_CANCEL)
    public void paymentCancel(ConsumerRecord<String,String> record){
        //  获取数据
        String orderNo = record.value();
        //  判断
        if (!StringUtils.isEmpty(orderNo)){
            paymentInfoService.closePayment(orderNo);
        }
    }
}
